<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	
	//前台首页页面
    public function index($bang='cbang'){

        //判断前台传过来的信息
        $banga = I('get.action');
        if(!empty($banga)){
            $bang = I('get.action');
        }
    	//调用分类类
    	$this->fenlei();

        //调用重磅推荐
        $this->zhongbang();

        //调用新书模块
        $this->xinshu();

        //调用榜单选项
        $this->bangdan($bang);

        //精品推荐
        $this->jptuijian();

    	//跳转到首页
        $this->display();


      
    }

    //首页左侧分类展示
    public function fenlei()
    {
    	//实例化model类
    	$fenlei = M('book_types');

    	//查询出所有的分类
    	$data = $fenlei->where('status=1 and pid=0')->select();

    	//赋值变量
    	$this->assign('fenlei',$data);
    }
   
   //重磅推荐
    public function zhongbang()
    {
        //实例化model
        $zhongbang = M('book');

        //查询数据库
        $zhongbanga = $zhongbang->limit('2')->order('zbang desc')->select();
        
        //赋值变量
        $this->assign('zhongbang',$zhongbanga);
    }

    //重磅新书
    public function xinshu()
    {
        //实例化model类
        $xinshu = M('book');

        //查询数据库
        $newbook = $xinshu->limit('5')->order('newbook desc')->select();
        
        //赋值变量
        $this->assign('newbook',$newbook);
    }

    //榜单
    public function bangdan($bang){

        //连接数据库
        $bangdan = M('book');

        //查询数据库中所有信息
        $data = $bangdan->limit('10')->order("$bang desc")->select();

        //赋值变量
       $this->assign('bang',$data);
    
}


        //精品推荐
        public function jptuijian(){
            
            //实例化model类
            $jptuijian = M('book');

            //查询出所有的符合条件的书籍
            $data = $jptuijian->limit('14')->select();

            //赋值变量
            $this->assign(jptuijian,$data);
        }


}